package com.showsu.editor.utils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: William
 * @Description: 符合百度营销要求的接口响应结构体
 * @Date: Created in 2022/8/29 9:16 下午
 * @Modified By:
 */
public class BaiduResult extends HashMap<String, Object> implements Serializable {
    private static final long serialVersionUID = -9203803227066443076L;

    public static final String CODE_KEY = "code";

    public static final String MSG_KEY = "msg";

    public static final String DATA_KEY = "result";

    public BaiduResult() {
        put(CODE_KEY, 0);
        put(MSG_KEY, "success");
    }

    public static BaiduResult success() {
        BaiduResult r = new BaiduResult();
        r.put(CODE_KEY, 0);
        r.put(MSG_KEY, "success");
        return r;
    }

    public static BaiduResult success(String scheme) {
        BaiduResult r = new BaiduResult();
        r.put(CODE_KEY, 0);
        r.put(MSG_KEY, "success");
        Map<String, String> content = new HashMap<>();
        content.put("scheme", scheme);
        r.put(DATA_KEY, content);
        return r;
    }

    public static BaiduResult error() {
        return error(500, "error");
    }

    public static BaiduResult error(String msg) {
        return error(500, msg);
    }

    public static BaiduResult error(int code, String msg) {
        BaiduResult r = new BaiduResult();
        r.put(CODE_KEY, code);
        r.put(MSG_KEY, msg);
        return r;
    }

    @Override
    public BaiduResult put(String key, Object value) {
        super.put(key, value);
        return this;
    }

}
